{% extends "base.html" %}
{% block content %}
<div class="container mt-4">
    <div class="d-flex align-items-center justify-content-between mb-4">
        <div class="d-flex align-items-center">
            <i class="bi bi-chat-left-text fs-3 text-primary me-2"></i>
            <h2 class="mb-0">沟通纪要管理</h2>
        </div>
        <div class="d-flex gap-2">
            <a href="{{ url_for('communication.export_communications') }}" class="btn btn-outline-success">
                <i class="bi bi-file-earmark-excel"></i> 导出Excel
            </a>
            <a href="{{ url_for('communication.create') }}" class="btn btn-primary">
                <i class="bi bi-plus-circle"></i> 新建纪要
            </a>
        </div>
    </div>

    <!-- 筛选和统计 -->
    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="input-group search-bar">
                <span class="input-group-text"><i class="bi bi-search"></i></span>
                <input type="text" class="form-control" placeholder="搜索纪要ID或部门...">
            </div>
        </div>
        <div class="col-md-8 d-flex gap-2 justify-content-end">
            <select class="form-select" style="width: auto;">
                <option>全部部门</option>
                <option>技术部</option>
                <option>产品部</option>
                <option>运营部</option>
            </select>
            <select class="form-select" style="width: auto;">
                <option>全部沟通方式</option>
                <option>线上会议</option>
                <option>线下会议</option>
                <option>电话沟通</option>
            </select>
            <button class="btn btn-outline-secondary">高级筛选</button>
        </div>
    </div>

    <div class="card shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="table-light">
                        <tr>
                            <th class="ps-4">ID</th>
                            <th>时间</th>
                            <th>部门</th>
                            <th>提出人</th>
                            <th>方式</th>
                            <th>关联需求</th>
                            <th class="text-end pe-4">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for comm in communications %}
                        <tr>
                            <td class="ps-4">
                                {{ comm.comm_id }}
                            </td>
                            <td>{{ comm.meeting_time.strftime('%Y-%m-%d %H:%M') }}</td>
                            <td>
                                <i class="bi bi-building me-1"></i>
                                {{ comm.department }}
                            </td>
                            <td>
                                <i class="bi bi-person me-1"></i>
                                {{ comm.proposer }}
                            </td>
                            <td>
                                {% if comm.method == '线上会议' %}
                                    <span class="badge bg-info">{{ comm.method }}</span>
                                {% elif comm.method == '线下会议' %}
                                    <span class="badge bg-success">{{ comm.method }}</span>
                                {% else %}
                                    <span class="badge bg-warning text-dark">{{ comm.method }}</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if comm.related_req_id %}
                                <a href="{{ url_for('requirements.detail', req_id=comm.related_req_id) }}" 
                                   class="badge bg-primary text-decoration-none">
                                    #{{ comm.related_req_id }}
                                </a>
                                {% else %}
                                <span class="badge bg-secondary">未关联</span>
                                {% endif %}
                            </td>
                            <td class="text-end pe-4">
                                <div class="d-flex justify-content-end gap-1">
                                    <a href="{{ url_for('communication.edit', comm_id=comm.comm_id) }}" 
                                       class="btn btn-sm btn-outline-primary">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <form action="{{ url_for('communication.delete', comm_id=comm.comm_id) }}" 
                                          method="post" class="d-inline">
                                        <button type="submit" class="btn btn-sm btn-outline-danger"
                                                onclick="return confirm('确定删除此沟通纪要？')">
                                            <i class="bi bi-trash"></i>
                                        </button>
                                    </form>
                                    <!-- 暂时移除详情按钮，因为尚未实现对应的路由 -->
                                    <!-- 
                                    <a href="{{ url_for('communication.detail', comm_id=comm.comm_id) }}" 
                                       class="btn btn-sm btn-outline-info">
                                        <i class="bi bi-eye"></i>
                                    </a>
                                    -->
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            
            <!-- 空状态 -->
            {% if not communications %}
            <div class="text-center py-5">
                <i class="bi bi-inbox fs-1 text-muted"></i>
                <p class="mt-2 text-muted">暂无沟通纪要</p>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}